﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using imaginecup.information;
using imaginecup.objectManager;
using Imaginecup.util;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Imaginecup.util.input;
using Microsoft.Xna.Framework.Input.Touch;
using Imaginecup.util.collision;
using Imaginecup.sprite;

namespace Imaginecup.util
{
    public class ParticleMan 
    {
        
        private List<Particle> m_ParticleList = new List<Particle>();
        private static ParticleMan m_ParticleMan = null;

        private ParticleMan(){}       

        public static ParticleMan GetParticleMan()
        {
            if( m_ParticleMan == null )
            {
                m_ParticleMan = new ParticleMan();
            }
            return m_ParticleMan;
        }
        
        public void AddParticle(Particle particle)
        {
            m_ParticleList.Add(particle);
        }

        public int GetCount(ParticleType type)
        {
            int count = 0;
            foreach( Particle particle in m_ParticleList )
            {
                if( particle.GetParticleType() == type)
                {
                    count++;
                }
            }
            return count;
        }

        public void Update(GameTime gameTime)
        {
            UpdateParticle(gameTime);
        }

        private void UpdateParticle(GameTime gameTime)
        {
            for (int count = m_ParticleList.Count - 1; count >= 0; count--)
            {
                Particle p = m_ParticleList[count];

                if (p.Update(gameTime) == false)
                    m_ParticleList.Remove(p);

            }
        }
               
   
        public void Draw(SpriteBatch sb )
        {
            foreach( Particle p in m_ParticleList )
            {
                p.Draw(sb);
            }
        }

        public void Release()
        {
            m_ParticleList.Clear();
        }
    }
}
